<template>
	<view class="contont">
		<nav-bar :title="title" :iconLeft="true" />

		<view class="content-bgc">
			<view class="b-con">

				<view style="margin-top: 20rpx;">
					<up-cell-group :border="false">
						<up-cell title="采购退货单号">
							<template #value>
								<view class="cell-text">{{ detail_record.code }} </view>
							</template>
						</up-cell>
						<up-cell title="采购单号">
							<template #value>
								<view class="cell-text">{{ detail_record.purchase_order }} </view>
							</template>
						</up-cell>
						<up-cell title="采购数量">
							<template #value>
								<view class="cell-text">{{ mar_or.order_num }} </view>
							</template>
						</up-cell>
						<up-cell title="下单日期">
							<template #value>
								<view class="cell-text">{{ mar_or.order_date }} </view>
							</template>
						</up-cell>
						<up-cell title="退货日期">
							<template #value>
								<view class="cell-text">{{ detail_record.sales_date }}</view>
							</template>
						</up-cell>
						<up-cell title="备注">
							<template #value>
								<view class="cell-text" style="width: 70%;">{{ detail_record.desc }}</view>
							</template>
						</up-cell>
					</up-cell-group>
				</view>
			</view>
			<view class="b-con">
				<up-cell-group :border="false">
					<up-cell :isLink="true" :border="false" :title="`物料：总数量（${car_list.length}）`" @click="car_popupShow = true">
						<template #value>
							<view class="cell-text">点击查看 </view>
						</template>
					</up-cell>
				</up-cell-group>
			</view>
			<custom-popup :popupShow="car_popupShow" mode="bottom" :title="'物料'" class="car-popup-custom"
				@close="car_popupShow = false" height="70vh">
				<z-paging v-if="car_popupShow" ref="paging_car" :refresher-enabled="false" :loading-more-enabled="false" :fixed="false" v-model="car_list"
					@query="queryList_car">
					<uni-card v-for="(item, index) in car_list" :key="index" :title="item.name" :sub-title="item.code"
						margin="5px" spacing="0">
						<view class="ctent">规格：{{ item.specification }}</view>
						<view class="ctent ">供应商：{{ item.supplier_name }}</view>
						<view class="con">
							<view class="ctent ">采购价(元)：{{ item.supplier_price }}</view>
							<view class="ctent ">采购数量：{{ item.num }}</view>
						</view>
						<view class="con">
							<view class="ctent ">采购单位：{{ item.out_unit }}</view>
							<view class="ctent ">出货仓库：{{ item.warehouse_name }}</view>
						</view>
						<view class="con">
							<view class="ctent ">优惠率（%）：{{ item.discount }}</view>
							<view class="ctent ">总金额：{{ item.total_price }}</view>
						</view>
						<view class="con">
							<view class="ctent ">已入库量：{{ item.already_num }}</view>
							<view class="ctent ">已退货量：{{ item.sales_num }}</view>
						</view>
						<view class="con">
							<view class="ctent ">当前退货量：{{ item.now_num }}</view>
							<view class="ctent ">退货总金额：{{ item.now_price }}</view>
						</view>

					</uni-card>
				</z-paging>
			</custom-popup>
		</view>
	</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import puOutApi from '../../../api/purchase/pu_out'

const detail_record = ref({})
const title = '采购退货详情';
onLoad(option => {
	get_detail(option.id);
})

const mar_or = reactive({
	order_num: '',
	order_date: '',
})
function get_detail(id) {
	puOutApi.purchase_sales_detail(id).then(res => {
		detail_record.value = res
		mar_or.order_date = res.order_date
		mar_or.order_num = res.order_num
		car_list.value = res.purchase_sales_order_boms.map(v => {
			return {
				id: v.bom.id,
				code: v.bom.code,
				name: v.bom.name,
				specification: v.bom.specification,
				cost: v.cost,
				all_cost: v.bom.all_cost,
				main_price: v.main_price,
				num: v.purchase_num,
				all_price: v.all_price,
				discount: parseFloat(v.discount),
				now_price: v.now_price,
				total_price: v.total_price,
				already_num: v.already_num,
				sales_num: v.sales_num || 0,
				out_unit: v.out_unit,
				supplier_name: v.supplier_name,
				supplier_price: v.supplier_price,
				supplier_id: v.supplier_id,
				warehouse_name: v.warehouse_name,
				now_num: v.now_num
			}
		})
	})
}

const car_popupShow = ref(false)
const car_list = ref([])
const paging_car = ref(null)
function queryList_car() {
	paging_car.value.complete(car_list.value);
}
</script>
